Imports System.Xml.Serialization
Imports EdmxEditor.CodeGeneration

Namespace CSDL

    Public Class ComplexTypeProperty
        Inherits EntityPropertyBase

        ''' <summary>Initializes an instance of the <see cref="ComplexTypeProperty" /> class.
        ''' This is the default constructor for this class.</summary>
        Public Sub New()
            MyBase.New("Property", EdmXmlNamespace)
        End Sub

        ''' <summary>Initializes an instance of the <see cref="ComplexTypeProperty" /> class.</summary>
        ''' <param name="other">An <see cref="System.Xml.Linq.XElement"/> object to copy from.</param>
        Public Sub New(ByVal other As XElement)
            MyBase.New(other)
        End Sub

        ''' <summary>
        ''' Returns a value indicating if the property is a key.
        ''' </summary>
        ''' <returns><c>True</c> if the property is a key; <c>False</c> otherwise.</returns>
        Public Overrides Function IsKey() As Boolean
            Dim type = TryCast(Me.Parent, EntityType)
            If (type IsNot Nothing) Then
                Return type.Key.PropertyReferences.Where(Function(x) x.Name = Me.Name).Count > 0
            End If
            Return False
        End Function

        <XmlAttribute()> _
        Public Property ConcurrencyMode() As ConcurrencyMode
            Get
                Return GetEnumValueAttribute(GetType(ConcurrencyMode), Me.GetXAttribute("ConcurrencyMode"))
            End Get
            Set(ByVal value As ConcurrencyMode)
                SetEnumValueAttribute(GetType(ConcurrencyMode), Me.GetXAttribute("ConcurrencyMode", True), value)
            End Set
        End Property

        <XmlAttribute(Form:=System.Xml.Schema.XmlSchemaForm.Qualified, [Namespace]:=CodeGenerationXmlNamespace)> _
        Public Property SetterAccess() As Access
            Get
                Return GetEnumValueAttribute(GetType(Access), Me.GetXAttribute(CodeGenerationXmlNamespace, "SetterAccess"))
            End Get
            Set(ByVal value As Access)
                SetEnumValueAttribute(GetType(Access), Me.GetXAttribute(CodeGenerationXmlNamespace, "SetterAccess", True), value)
            End Set
        End Property

        <XmlAttribute(Form:=System.Xml.Schema.XmlSchemaForm.Qualified, [Namespace]:=CodeGenerationXmlNamespace)> _
        Public Property GetterAccess() As Access
            Get
                Return GetEnumValueAttribute(GetType(Access), Me.GetXAttribute(CodeGenerationXmlNamespace, "GetterAccess", True))
            End Get
            Set(ByVal value As Access)
                SetEnumValueAttribute(GetType(Access), Me.GetXAttribute(CodeGenerationXmlNamespace, "GetterAccess", True), value)
            End Set
        End Property

    End Class

End Namespace